package com.demo.service.impl;

import com.demo.dao.StudentRepository;
import com.demo.pojo.Student;
import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName StudentServiceImpl
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/17 14:43
 * @Version 1.0
 **/
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentRepository studentRepository;
    @Override
    public List<Student> findAll() {
        return studentRepository.findAll();
    }

    @Override
    public boolean delStudent(int id) {
        try{
            studentRepository.deleteById(id);
        }catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public Student findOne(int id) {
        return studentRepository.findById(id);
    }

    @Override
    public boolean editStu(Student student) {
        Student stu = studentRepository.saveAndFlush(student);
        if (stu != null) {
             return true;
        }
        return false;
    }
}
